package com.example.innelop

import org.junit.Test

/**
 * <pre>
 * author : zhouronghua
 * e-mail : zhouronghua01@dreamxr.com
 * time : 2023/04/07
 * desc : 与takeIf类似，只是功能相反。参数是it
 * name.takeUnless { true/false }   false: 返回name 否则返回空
 * version: 1.0
 * </pre>
 */

class Manager {
    private var infoValue: String? = null

    fun getInfoValue() = infoValue

    fun setInInfoValue(infoValue: String) {
        this.infoValue = infoValue
    }
}

class TakeUnlessTest {

    @Test
    fun testUnless() {
        val manager: Manager = Manager()
        // takeUnless: true返回空值，采用空合并操作符定义内容
        val r = manager.getInfoValue().takeUnless {
            it.isNullOrBlank()
        } ?: "未经过任何初始化处理"
        println(r)
    }

}